<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
Refresh = function(){
	$(".ajax_purchase_order").autocomplete("<?=url('Storage::Overseas/PurchaseOrderAjax')?>").result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent().parent();
			container.find("input.number").val(data[0]);
			container.find("input.purchase_order_id").val(data['id']);
		}
	});
};
$(function(){
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".delete").live("click", function(){
		$(this).parent().parent().parent().parent().remove();
	});
	var i=0;
	$("#add_item").click(function(){
		var _html = "<table width='100%' class='list_table'>";
		_html += "<tr><td align='left' colspan='6'><label><input type='checkbox' class='is_checked' checked='checked' /> <span>采购单号</span></label>";
		_html += " <input type='text' size='14' disabled='disabled' class='number' />";
		_html += " <input type='text' size='14' class='ajax_purchase_order' />";
		_html += "<input type='hidden' class='purchase_order_id' name='item[new_" + i + "]' />";
		_html += "<td><a class='delete'>删除</a></td></tr></table>";
		$("#item_list").append(_html);
		Refresh();
		i++;
	});
	$("#add_save").click(function(){
		var can_save = 1;
	 	//检测是否需要提交数据
		$("#item_list").find("input.is_checked").each(function(){
			if (!$(this).is(":checked"))
			{
				$(this).parent().parent().parent().parent().remove();
			}
		});
		if (can_save)
		{
			$("form").submit();
		}
	});
	Refresh();
});
</script>
<form method="post" action="<?=url('Storage::Overseas/SendEditSave')?>">
<fieldset>
	<table class="form_table">
		<tr>
			<th>仓库</th>
			<td><?=$send_order['warehouse_name']?></td>
			<th>包裹数</th>
			<td>
			<input type="text" name="package_quantity" value="<?=$send_order['package_quantity']?>" />
			<input type="hidden" name="id" value="<?=$send_order['id']?>" />
			</td>
			<th>产品数</th>
			<td><input type="text" name="product_quantity" value="<?=$send_order['product_quantity']?>" /></td>
			<th>重量</th>
			<td><input type="text" name="weight" value="<?=$send_order['weight']?>" /></td>
			<th>体积</th>
			<td><input type="text" name="volume" value="<?=$send_order['volume']?>" /></td>
		</tr>
		<tr>
			<th>物流公司</th>
			<td><input type="text" name="express_company" value="<?=$send_order['express_company']?>" /></td>
			<th>物流单号</th>
			<td><input type="text" name="express_number" value="<?=$send_order['express_number']?>" /></td>
			<th>追踪号</th>
			<td><input type="text" name="tracking_number" value="<?=$send_order['tracking_number']?>" /></td>
		</tr>
		<tr>
			<th>发送时间</th>
			<td><input type="text" name="send_time" value="<?=$send_order['send_time']?>" class="datepicker" /></td>
			<th>预计入库时间</th>
			<td><input type="text" name="budget_storage_time" value="<?=$send_order['budget_storage_time']?>" class="datepicker" /></td>
			<th>实际入库时间</th>
			<td><input type="text" name="actual_storage_time" value="<?=$send_order['actual_storage_time']?>" class="datepicker" /></td>
		</tr>
		<tr>
			<th>备注</th>
			<td colspan="3"><textarea rows="3" cols="60" name="notes"><?=$send_order['notes']?></textarea></td>
		</tr>
	</table>
</fieldset>
<div id="item_list">
<?foreach ($purchase_order as $k => $po):?>
<table width="100%" class="list_table">
	<tr>
		<td align="left" colspan="6">
			<label><input type="checkbox" class="is_checked" checked="checked" /> <span>采购单号</span></label>
			<input type="text" size="14" disabled="disabled" class="number" value="<?=$po['number']?>" />
			<input type="text" size="14" title="<?=$po['number']?>" class="ajax_purchase_order" value="<?=$po['number']?>" />
			<input type="hidden" name="item[<?=$k?>]" class="purchase_order_id" value="<?=$po['purchase_order_id']?>" />
		</td>
		<td><a class="delete">删除</a></td>
	</tr>
</table>
<?endforeach;?>
</div>
<input type="hidden" name="history" value="<?=$_SERVER['HTTP_REFERER']?>" />
<div align="left"><a id="add_item">添加采购单</a></div>
<div align="center"><input type="button" class="button" id="add_save" value="保存发送单" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock();?>